/**
 * Created by haocongshun on 2016/8/9.
 */
$(function () {
    $("#projectTop").show();
    $("#projectTable").show();
    $("#setTop").hide();
    $("#setFrom").hide();
    getAll();

});
function getAll() {
    var url = "/TaskCollection/Projectprogress/studentGetAll.wst";
    var dataAll = {};
    var resultuse = "";
    $.ajaxSetup({
        async : false
    });
    $.post(url,dataAll,function (result) {
        $("#projectTop span").text(result.project.project_name+"项目的进度列表");
        for(var i  = 0;i < result.getAll.length;i++){
            var newrow = "<tr>" +
                "<td class='date' data-i='"+i+"'>"+result.getAll[i].projectProgress_date+"</td>" +
                "<td>"+result.getAll[i].projectProgress_name+"</td>" +
                "<td ><a href='/TaskCollection/Projectprogress/download.wst?id="+result.getAll[i].projectProgress_id+"'>"+result.getAll[i].projectProgress_file+"</a></td>" +
                "<td><input class='btn see' type='button' value='查看'></td> " +
                "<td><input class='btn del' type='button' value='删除'></td>" +
                "</tr>";
            $("#progress tr:last").after(newrow);
        }
        resultuse=result;

    },"json");
    bindsee_del(resultuse);
    $("#add").click(function () {
        if(resultuse.project.student.student_name==resultuse.project.projectTeam.projectTeamLeader.student_name){
            location.href="/TaskCollection/student/addProgress.jsp?id="+resultuse.project.project_id;
        }else {
            alert("你不是项目组长，没有此权限！");
        }
        
    });
}
function bindsee_del(resultlast) {
    $(".see").click(function () {
        $("#projectTop").hide();
        $("#projectTable").hide();
        $("#setTop").show();
        $("#setFrom").show();
        var i = $(this).parent().parent().children(".date").attr("data-i");
        $("#name span").text(resultlast.getAll[i].projectProgress_name);
        $("#time span").text(resultlast.getAll[i].projectProgress_date);
        $("#content textarea").text(resultlast.getAll[i].projectProgress_content);
        $("#see-back").click(function () {
            $("#projectTop").show();
            $("#projectTable").show();
            $("#setTop").hide();
            $("#setFrom").hide();
            $("#progress tr:not(:first)").html("");
            getAll();
        });
    });
    $(".del").click(function () {
        var i = $(this).parent().parent().children(".date").attr("data-i");
        var id = resultlast.getAll[i].projectProgress_id;
        var dataDel = {};
        dataDel.id = id;
        var url="/TaskCollection/Projectprogress/del.wst"
        var flag;
        $.ajaxSetup({
            async : false
        });
        $.post(url,dataDel,function (result) {
            flag=result.msg;
        },"json");
        if(flag==true){
            $(this).parent().parent().remove();
        }else {
            alert("请求失败！");
        }
    });
}